package com.wallet.provider.service.impl;


import com.github.pagehelper.Page;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wallet.common.vo.PageResult;
import com.wallet.provider.mapper.SysUserMapper;
import com.wallet.provider.model.SysUser;
import com.wallet.provider.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.Date;
import java.util.List;


@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public boolean validUserId(String username) {
        SysUser sysUser = sysUserMapper.selectSysUserByUsername(username);
        return sysUser== null;
    }

    @Override
    public PageInfo   getSysUserList(String keywords, int pageNum, int pageSize, String orderName, String orderType) {
        List<SysUser> sysUsers = sysUserMapper.selectByPageNumSize(keywords, pageNum, pageSize, orderName, orderType);
        return new PageInfo<>(sysUsers);
    }

    @Override
    public boolean addSysUser(SysUser sysUser) {
        sysUser.setCreateTime(new Date());
        sysUser.setPassword(DigestUtils.md5Hex(sysUser.getPassword()));
        int count = sysUserMapper.insertSelective(sysUser);
        return count > 0;
    }


    @Override
    public boolean deleteSysUser(String ids) {
        return sysUserMapper.deleteByIds(ids) > 0;
    }

    @Override
    public boolean updateSysUser(SysUser sysUser) {
        return sysUserMapper.updateByPrimaryKeySelective(sysUser) > 0;
    }

    @Override
    public SysUser getSysUserByUsername(String username) {
        return sysUserMapper.selectSysUserByUsername(username);
    }

    @Override
    public SysUser getSysUserById(Long id) {
        return sysUserMapper.selectByPrimaryKey(id);
    }
}
